#include "queue.h"
#include <shr.h>
#define q_i queue_insert
#define q_p queue_push
#define q_s queue_setsize
#define q_e queue_empty
int n,m;
queue a;
int main(void){
    int i,x;
    freopen("queue.in","r",stdin);
    freopen("queue.out","w",stdout);
    scanf("%d%d",&n,&m);
    q_s(&a,sizeof(int));
    for (i=1;i<=n;++i){
        scanf("%d",&x);
        q_i(&a,x);
    }
    printf("%d ",q_e(a));
    for (i=1;i<=m;++i){
        scanf("%d",&x);
        if (x==-1)
           printf("%d\n",q_p(&a));
        else
            q_i(&a,x);
    }
    for (i=a.begin();i<a.end();++i)
        printf("%d ",a.val[i]);
    return 0;
}
